<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
cfc('core')->checklogin();
$return=array();
if($_RQ['op']=='main'){
	$return['setting']=$this->plugin_setting('basic');
	$return['list']=array();
	set_html('title','服务评论');
	exi($return);
}
if($_RQ['op']=='commentorder'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('订单不存在，请重新选择订单','error');
	}	
	$order=pdo_get('jy_aikefu_tcp',array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
	//技师
	$worker=pdo_get('jy_aikefu_worker',array('uniacid'=>$_SESSION['uniacid'],'id'=>$order['workerid']));	
	$worker['logo']=tomedia($worker['logo']);
	$worker['ordersum']=pdo_count('jy_aikefu_tcp',array('uniacid'=>$_SESSION['uniacid'],'workerid'=>$order['workerid']));
	$return['order']=$order;
	$return['worker']=$worker;
	$comment=pdo_get('jy_aikefu_comment',array('uniacid'=>$_SESSION['uniacid'],'tcpid'=>$order['id']));
	if($comment['id']){
		$return['isping']=1;
	}
	$return['post']=$comment?:array('star'=>5,'tcpid'=>$order['id'],'workerid'=>$worker['id']);
	$return['post']['images']=$return['post']['images']?json_decode($return['post']['images'],true):array();
	exi($return);
}

if($_RQ['op']=='submit'){
	$postdata=get_postdata();
	$data=array(
		'msg'=>$postdata['msg'],
		'images'=>ijson_encode($postdata['images']),
		'star'=>intval($postdata['star']),
	);
	$comment_id=$this->pdo_getcolumn('comment',array('uniacid'=>$_SESSION['uniacid'],'tcpid'=>intval($postdata['tcpid'])),'id');
	$basic=$this->plugin_setting('basic');
	$show=$basic['shenhe']?0:1;
	if($comment_id){
		$this->pdo_update('comment',$data,array('id'=>$comment_id));
	}else{
		$insert=array(
			'uniacid'=>$_SESSION['uniacid'],
			'mid'=>$_SESSION['uid'],
			'show'=>$show,
			'workerid'=>intval($postdata['workerid']),
			'tcpid'=>intval($postdata['tcpid']),
			'createtime'=>TIMESTAMP,
		);
		$data=array_merge($insert,$data);
		$this->pdo_insert('comment',$data);
		$this->update('tcp',array('iscomment'=>1),array('id'=>$insert['id'],'uniacid'=>$_SESSION['uniacid']));
	}
	exi('评价成功！','','goback');
}
?>